new Vue({
  el: '#app',
  data() {
    return {
      form: {
        serachKey: "",
        page: 1,			//页数
        limit: 10			//每页数据条数
      },
      formData: {},
      tableData: [{
        Sales_Unit_Price_SerialNumber: "3423424234",  //主键,账单号
        TotalAmount: '1111111',  //总金额
        Account: '333333',   //账户
        AllocateTime: '2014-05-07',  //分配时间
        RemainingAmount: '51455',   //剩余金额
        Enterprise_Info_SerialNumber: $.cookie("enterprise"),
        Children: {
          sales_unitprice_detail: [{
            Sales_Unit_Price_Detail_SerialNumber: "15151",   //主键
            Supplier_Name: '东货郎',  //供应商
            Row_Status: '0',  //分配状态
            EndDate: '2024-05-12',   //结算日期
            AllocationRatio: '33333',  //分配比例
            CollectionAccount: '44444',  //收款账户
          }],
          sales_unitprice_storescope: [{     //门店信息
            Sales_Unit_Price_StoreScope_SerialNumber: "555155",  //主键
            Store_Name: '哇哈哈', //门店名称
            Row_Status: '1',  //分配状态
            EndDate: '2028-11-23',   //结算日期
            AllocationRatio: '55555',  //分配比例
            CollectionAccount: '66666',  //收款账户
          }],
        }
      }],		//表格数据
      total: 1,
      dialogForm: false,
      index: '',
      title: '',
      activeName: 'first',
      multipleSelection: []
    }
  },
  mounted() {
    // this.getList1()
    console.log(DomainName);
  },
  methods: {
    onSerach() {				//查询方法
      console.log("搜搜")
    },
    addContract() {
      console.log("跳转")
    },
    getList1() {
      let _this = this
      $.ajax({
        type: 'GET',
        data: { action: "jQueryAjax", token: $.cookie("token") },
        url: DomainName + '/SalesUnitprice_Entire',
        success: function (data) {
          _this.tableData = data;
          console.log(_this.tableData)
        },
        dataType: "json"
      });
    },
    getList() {     //换页方法
      let _this = this
      $.ajax({
        type: 'POST',
        //	url: "../getContractListByConditionAction",
        url: "../getListByTableNameAction",
        data: {
          Data: "enterprise_info"
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        success: function (Result) {
          console.log(Result);
          _this.tableData = Result      //将获取的数据存到表格数据中
        },
        dataType: "json"
      });
    },
    addEnterprise() {
      window.location.href = './Add.html'
    },
    showMember(Sales_Unit_Price_SerialNumber) {
      sessionStorage.setItem("Sales_Unit_Price_SerialNumber", Sales_Unit_Price_SerialNumber)
      window.location.href = './show.html?Sales_Unit_Price_SerialNumber=' + Sales_Unit_Price_SerialNumber
    },
    editMember(Sales_Unit_Price_SerialNumber) {
      sessionStorage.setItem("Sales_Unit_Price_SerialNumber", Sales_Unit_Price_SerialNumber)
      window.location.href = './Edit.html?Sales_Unit_Price_SerialNumber=' + Sales_Unit_Price_SerialNumber
    },
    //切换导航栏
    handleClick(tab, event) {
      console.log(tab.index);
      this.index = tab.index
    },
    // 展开供应商
    handleChildren(row) {
      _this = this
      console.log(row.Children.sales_unitprice_detail.length)
      console.log(row.Children.sales_unitprice_detail[0].Sales_Unit_Price_Detail_SerialNumber)
      if (!row.Children.sales_unitprice_detail.length) {
        // console.log(row.Children.sales_unitprice_detail.length)
        // $.ajax({
        //   url: DomainName + '/getSpecificationsAction',
        //   type: 'POST',
        //   data: {
        //     Sales_Unit_Price_Detail_SerialNumber: row.Sales_Unit_Price_Detail_SerialNumber,
        //     token: $.cookie("token")
        //   },

        //   success: function (data) {
        //     console.log(data)
        //     // data.forEach(item => {
        //     //   item.Picture_URL = DomainName + item.Picture_URL
        //     // })
        //     row.Children.article_specifications = data
        //     // console.log(expandedRows[expandedRows.length - 1].Children.article_specifications)
        //   },
        //   dataType: "json"
        // });
      }

    },
    // 展开店铺
    handleShop(row) {
      _this = this
      console.log(row.Children.sales_unitprice_storescope.length)
      console.log(row.Children.sales_unitprice_storescope[0].Sales_Unit_Price_StoreScope_SerialNumber)
      if (!row.Children.sales_unitprice_storescope.length) {
        // console.log(row.Children.sales_unitprice_detail.length)
        // $.ajax({
        //   url: DomainName + '/getSpecificationsAction',
        //   type: 'POST',
        //   data: {
        //     Sales_Unit_Price_Detail_SerialNumber: row.Sales_Unit_Price_Detail_SerialNumber,
        //     token: $.cookie("token")
        //   },

        //   success: function (data) {
        //     console.log(data)
        //     // data.forEach(item => {
        //     //   item.Picture_URL = DomainName + item.Picture_URL
        //     // })
        //     row.Children.article_specifications = data
        //     // console.log(expandedRows[expandedRows.length - 1].Children.article_specifications)
        //   },
        //   dataType: "json"
        // });
      }

    },
    onExcel() {
      /* generate workbook object from table */
      //  .table要导出的是哪一个表格
      var wb = XLSX.utils.table_to_book(document.querySelector("#out-table"));
      /* get binary string as output */
      var wbout = XLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array"
      });
      try {
        //  name+'.xlsx'表示导出的excel表格名字
        saveAs(
          new Blob([wbout], {
            type: "application/octet-stream"
          }),
          "销售价格单" + ".xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
    deletMember(Sales_Unit_Price_SerialNumber) {
      this.$confirm('此操作将删除该销售价格单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        this.delete(Sales_Unit_Price_SerialNumber);
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    delete(Sales_Unit_Price_SerialNumber) {
      const _this = this
      $.ajax({
        url: DomainName + '/SalesUnitpriceId',
        type: 'POST',
        data: { Data: Sales_Unit_Price_SerialNumber },
        success: function (res) {
          if (res.length == 1) {
            res[0].Row_Status = '1'
            let data = { Data: JSON.stringify({ Modify: { sales_unitprice: [res[0]] } }) };
            $.ajax({
              url: DomainName + '/GoodsFileEdit',
              type: 'POST',
              data,
              success: function (re) {
                if (re.Status == "success") {
                  _this.$message.success("作废成功")
                  _this.getList1();
                }
              },
              error: function () {
                _this.$message.error("删除失败，请稍后再试")
              },
              complete: function () { _this.loading = false }
            })
          }
        }
      })
    }
  },
})